<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="theme-color" content="#111" />
    <meta name="description" content="A Tetris game, running on the web, responsive and installable." />
    <title>QQ登录回调处理</title>
    <script>
        // 捕获QQ返回的Token（URL hash模式）
        const parseToken = () => {
            const hash = window.location.hash.substring(1);
            const params = new URLSearchParams(hash);
            const data = {
                access_token: params.get('access_token'),
                openid: params.get('openid'),
                state: params.get('state')
            }
            console.log('data', data)
            return data;
        };

        const url = 'http://miriru.asia'
        // const url = 'http://localhost:5173/'

        window.onload = () => {
            const { access_token, state } = parseToken();
            if (access_token) {
                // 发送结果回SPA主窗口
                if (window.opener) {
                    window.opener.postMessage({
                        type: 'qqLoginSuccess',
                        token: access_token,
                        state: state
                    }, url); // 替换为你的SPA域名
                }
            }
            window.close(); // 自动关闭回调页
        };
    </script>
</head>

<body>
    <p>正在处理QQ登录，请稍候...</p>
</body>

</html>